import { syncSetTimeout, sendMessage, getMessage, dispatch } from "../../global/tools.js";

export default class AjaxHook {
    static count = 0;
    constructor(webController) {
        AjaxHook.count++;
        if (AjaxHook.count >= 2) {
            alert("collectionPlugin: \nError: AjaxHook.count >= 2，即将刷新页面。");
            location.reload(true);
        } 
        this.webController = webController;
        this.config = {
            blackList: []
        }
        this.init();
    }
    init() {
        const origPushState = history.pushState;
        history.pushState = function() {
            const result = origPushState.apply(this, arguments);
            this.checkBlack(window.location.href);
            return result;
        };
    }
    checkBlack(url) {
        this.config.blackList.forEach(item => {
            if (url.includes("/" + item)) {
                this.webController.auto.config.autoCall = false;
                alert("collectionPlugin: \nError: 检测到黑名单，即将刷新页面。"); 
            }
        });
    }
}